<template>
  <div>
    <el-card class="box-card">
      <el-table :data="tableData" :header-cell-style="{ textAlign: 'center' }" align="center" header-align="center"
        style="width: 100%">
        <el-table-column prop="id" label="ID" align="center" width="50px" />
        <el-table-column label="设备种类" align="center">
          <template #default="scope">
            <el-select v-model="scope.row.eqtype" placeholder="选择设备类型" style="width: 140px">
              <el-option v-for="item in eqTypeOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="设备种类" align="center" width="110px">
          <template #default="scope">
            <el-radio-group v-model="scope.row.ta_net_type" class="ml-4">
              <el-radio label="采集器电表">采集器电表</el-radio>
              <el-radio label="无线电表">无线电表</el-radio>
            </el-radio-group>
          </template>
        </el-table-column>
        <el-table-column label="通信方式" align="center">
          <template #default="scope">
            <el-select v-model="scope.row.communication" placeholder="选择通信方式" style="width: 140px">
              <el-option v-for="item in communicationOptions" :key="item.value" :label="item.label"
                :value="item.value" />
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="抄表选项" align="center">
          <template #default="scope">
            <el-select v-model="scope.row.meter_option" placeholder="选择抄表选项" multiple style="width: 240px">
              <el-option v-for="item in meterOptions" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </template>
        </el-table-column>
      </el-table>
      <div class="center">
        <el-button type="primary" @click="saveClick(); emit('saved')">保存</el-button>
        <el-button color="#626aef" @click="emit('completed')">返回</el-button>
        <!-- 
          用slot + buttom来实现父组件控制子组件还是第一次见到挺骚的XD TODO:记得删除这注释XD
          <slot></slot>
        -->
      </div>
    </el-card>
    <!-- 确认更改弹出框, 此弹窗可以用ElMessageBox替代 -->
    <!-- <el-dialog v-model="isShowChangeConfirm" title="保存成功">
      <span>批量添加成功！点击确定后返回原页面。</span>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="emit('completed'); isShowChangeConfirm = false">确定</el-button>
        </span>
      </template>
    </el-dialog> -->
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "vue"
import { ElMessageBox } from 'element-plus'
const emit = defineEmits(['completed', 'saved'])
// 显示修改确认dialog
// const isShowChangeConfirm = ref(false);

// 表单数据
const tableData = reactive([
  {
    id: 1,
    eqtype: "a",
    ta_net_type: "采集器电表",
    communication: "LORA",
    meter_option: "单相电压,单相电流,频率",
  },
  {
    id: 2,
    eqtype: "b",
    ta_net_type: "无线电表",
    communication: "485",
    meter_option: "单相电压,单相电流,频率",
  },
  {
    id: 3,
    eqtype: "c",
    ta_net_type: "无线电表",
    communication: "蓝牙",
    meter_option: "单相电压,单相电流,频率",
  },
  {
    id: 4,
    eqtype: "d",
    ta_net_type: "采集器电表",
    communication: "其他",
    meter_option: "单相电压,单相电流,频率",
  },
  {
    id: 5,
    eqtype: "e",
    ta_net_type: "采集器电表",
    communication: "3G",
    meter_option: "单相电压,单相电流,频率",
  },
])
const communicationOptions = [
  {
    value: "LORA",
    label: "LORA",
  },
  {
    value: "485",
    label: "485",
  },
  {
    value: "蓝牙",
    label: "蓝牙",
  },
  {
    value: "3G",
    label: "3G",
  },
  {
    value: "4G",
    label: "4G",
  },
  {
    value: "其他",
    label: "其他",
  },
]
const meterOptions = [
  {
    value: "单相电压",
    label: "单相电压",
  },
  {
    value: "单相电流",
    label: "单相电流",
  },
  {
    value: "频率",
    label: "频率",
  },
  {
    value: "总电量",
    label: "总电量",
  },
  {
    value: "剩余金额",
    label: "剩余金额",
  },
]
const eqTypeOptions = [
  {
    value: "a",
    label: "a",
  },
  {
    value: "b",
    label: "b",
  },
  {
    value: "c",
    label: "c",
  },
  {
    value: "d",
    label: "d",
  },
  {
    value: "e",
    label: "e",
  },
]

async function saveClick() {
  // isShowChangeConfirm.value = true
  console.log('批量修改保存Click')
  await ElMessageBox.alert('批量添加成功！点击确定后返回原页面。', '保存成功', { showClose: false })
  emit('completed')
}
</script>
<style scoped>
.box-card {
  width: 85%;
  min-width: 900px;
}

.center {
  display: flex;
  justify-content: center;
  margin: 10px;
}

.el-button {
  width: 300px;
}

h5 {
  text-align: center;
}
</style>
